//显示回到顶部的li
$(window).scroll(function () {
    if ($(window).scrollTop() > 620) {
        $(".comeback ul li:nth-child(6)").show()
    } else {
        $(".comeback ul li:nth-child(6)").hide()
    }
})
//回到顶部
$(".comeback ul li:nth-child(6)").click(function () {
    $('html').animate({
        scrollTop: 0
    }, 800)
})

//鼠标进出改变图片
$(".comeback ul li:nth-child(1)").mouseenter(function () {
    $(".comeback ul li:nth-child(1) img").prop("src", "img/74c4fcb4475af8308e9a670db9c01fdf.png")
})

$(".comeback ul li:nth-child(1)").mouseleave(function () {
    $(".comeback ul li:nth-child(1) img").attr("src", "img/98a23aae70f25798192693f21c4d4039.png")
})


$(".comeback ul li:nth-child(2)").mouseenter(function () {
    $(".comeback ul li:nth-child(2) img").attr('src', 'img/41f858550f42eb1770b97faf219ae215.png')
})

$(".comeback ul li:nth-child(2)").mouseleave(function () {
    $(".comeback ul li:nth-child(2) img").attr('src', 'img/55cad219421bee03a801775e7309b920.png')
})

$('.comeback ul li:nth-child(6)').mouseenter(function () {
    $(".comeback ul li:nth-child(6) img").attr('src', "img/totop_hover.png")
}).mouseleave(function () {
    $(".comeback ul li:nth-child(6) img").attr('src', 'img/totop.png')
});


//==============图片阴影===============
(function () {
    $.fn.extend({
        moveUp: function () {
            // 插件功能
            // 调用该方法的jquery对象添加一个hover效果
            // 鼠标移入的时候，上移，添加阴影
            // 鼠标移出的时候，回到原来的位置，取出阴影
            // console.log(this);// this就是调用方法的那个jquery对象
            // 这个this是所有li的jquery对象
            this.css("transition", "all 0.5s");
            this.hover(function () {
                // 事件函数里面的this是当前移入的那个li节点，dom节点
                $(this).css({
                    transform: "translate3d(0px,-5px,0px)",
                    boxShadow: "0 15px 30px rgb(0 0 0 / 10%)"
                })
            }, function () {
                $(this).css({
                    transform: "translate3d(0px,0px,0px)",
                    boxShadow: "none"
                })
            })
        }
    })
})()
$('.box-cp-right ul li').moveUp();
$('.box-cp2-right ul li').moveUp();
$('.box-cp3-right ul li').moveUp();
$('.box-cp4-right ul li').moveUp();
$('.box-cp5-right ul li').moveUp();
$('.box-cp6-right ul li').moveUp();


//============二级菜单==============
$('.header-nav .top-nav li ').mouseenter(function () {
    // $('.header-nav .top-nav ul').css({'display':'block'})

    $('.header-nav .top-nav ul').finish()
    $('.header-nav .top-nav ul').slideDown()
})



$('.header-nav .top-nav li').mouseleave(function () {
    // $('.header-nav .top-nav ul').css({'display':'none'})
    $('.header-nav .top-nav ul').finish()
    $('.header-nav .top-nav ul').slideUp()
})

$('.header-nav .top-nav li:nth-of-type(8)').mouseenter(function () {
    // $('.header-nav .top-nav ul').css({'display':'none'})
    $('.header-nav .top-nav ul').finish()
    $('.header-nav .top-nav ul').hide()
})

$('.header-nav .top-nav li:nth-of-type(9)').mouseenter(function () {
    // $('.header-nav .top-nav ul').css({'display':'none'})
    $('.header-nav .top-nav ul').finish()
    $('.header-nav .top-nav ul').hide()
})



//移到每一个li 获取数据，生成小盒子
$('.header-nav .top-nav li:nth-of-type(1)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[0].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第二个
$('.header-nav .top-nav li:nth-of-type(2)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[1].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第三个
$('.header-nav .top-nav li:nth-of-type(3)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[2].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第四个
$('.header-nav .top-nav li:nth-of-type(4)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[3].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第五个
$('.header-nav .top-nav li:nth-of-type(5)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[4].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第六个
$('.header-nav .top-nav li:nth-of-type(6)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.topNav[5].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})

//第七个
$('.header-nav .top-nav li:nth-of-type(7)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            console.log(data)
            $.each(data.topNav[6].childs, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.a}</p><span>${d.i}</span></li>`).appendTo('.header-nav .top-nav ul')
            })

        }

    })
}).mouseleave(function () {
    $('.header-nav ul ul').empty() //删除li里面的子级
})



//===========左边的菜单==========
$('.header-nav .left-nav ').mouseenter(function () {
    // $('.header-nav .top-nav ul').css({'display':'block'})
    $('.header-nav .left-nav ul').finish()
    $('.header-nav .left-nav ul').show()
})


$('.header-nav .left-nav ').mouseleave(function () {
    // $('.header-nav .top-nav ul').css({'display':'none'})
    $('.header-nav .left-nav ul').finish()
    $('.header-nav .left-nav ul').hide()
})

//生成小盒子
$('.header-nav .left-nav li:nth-of-type(1)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[0].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(2)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[1].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(3)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[2].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(4)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[3].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(5)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[4].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(6)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[5].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(7)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[6].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(8)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[7].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(9)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[8].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

$('.header-nav .left-nav li:nth-of-type(10)').mouseenter(function () {
    $.ajax({
        url: "./nav.json",
        dataType: "json",
        success: function (data) {
            $.each(data.sideNav[9].child, function (i, d) {
                $(`<li><img src="${d.img}" alt=""><p>${d.title}</p></li>`).appendTo('.header-nav .left-nav ul')
            })
        }

    })
}).mouseleave(function () {
    $('.header-nav .left-nav ul').empty() //删除li里面的子级
})

//========秒杀==========
ms();
setInterval(ms,1000)

function ms(){

    var nowTime=new Date()
    // console.log(nowTime)
    
    var startTime=new Date('2021/05/30 23:00:00')
    // console.log(startTime.getTime()-nowTime.getTime())
    

    //场次
    var round=startTime.getHours();
    // console.log(round)
    $('#round').html(round+':00 场')


    var time=startTime-nowTime;
    time=parseInt(time/1000);//变成秒数
    console.log(time)

    var hour=parseInt(time/(60*60));
    console.log(hour)
    if(hour<10){
        hour="0"+hour
    }
    time=time-hour*(60*60)


    var min=parseInt(time/60);
    console.log(min)
    if(min<10){
        min="0"+min
    }
    time=time-min*60;

    var second=parseInt(time);
    if(second<10){
        second="0"+second
    }

    $('.ms-time span:nth-of-type(1)').html(hour)
    $('.ms-time span:nth-of-type(2)').html(min)
    $('.ms-time span:nth-of-type(3)').html(second)

}

//点击购物车跳转页面
$('.top-car').click(function(){
    $(location).attr("href","./car/car.html")
})

//点击轮播图下面的红米跳转到红米详情页面
$('.home-right li:nth-of-type(1)').click(function(){
    $(window).attr('location','redmi.html')
})

//跳转首页
$('.top-nav a:nth-of-type(1)').click(function(){
    $(location).attr('href','./index.html')
})

